﻿using System.Data;
using System.Data.SqlClient;

namespace VMukti.DataAccess
{
    public class ClsBuddyDataService : ClsDataServiceBase
    {

        public ClsBuddyDataService() : base() { }

        ////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///	Creates a new DataService and specifies a transaction with
        ///	which to operate
        /// </summary>
        ////////////////////////////////////////////////////////////////////////
        public ClsBuddyDataService(IDbTransaction txn) : base(txn) { }

        public DataSet Buddy_GetAll()
        {
            return ExecuteDataSet("Select * vMyBuddy;", CommandType.Text, null);
        }

        public DataSet Buddy_GetByID(int ID)
        {
            return ExecuteDataSet("spGMyBuddy", CommandType.StoredProcedure, 
                CreateParameter("@pID", SqlDbType.Int, ID));
        }

        public DataSet Buddy_GetByUserID(int UserID)
        {
            return ExecuteDataSet("spGMyBuddyByUserID", CommandType.StoredProcedure,
                CreateParameter("@pID", SqlDbType.Int, UserID));
        }

        public void Buddy_Save(ref int ID, int MyUserID, int UserID)
        {
            SqlCommand cmd;
            ExecuteNonQuery(out cmd, "spAEMyBuddy",
                CreateParameter("@pID", SqlDbType.Int, ID, ParameterDirection.InputOutput),
                CreateParameter("@pMyUserID", SqlDbType.Int, MyUserID),
                CreateParameter("@pUserID", SqlDbType.Int, UserID));

            ID = int.Parse(cmd.Parameters["@pID"].Value.ToString());

            cmd.Dispose();
        }

        public void Buddy_Delete(int ID)
        {
            ExecuteNonQuery("spDMyBuddy", CreateParameter("@pID", SqlDbType.Int, ID));
        }

    }
}
